///https://leetcode.cn/problems/max-consecutive-ones-iii/description/

class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int left = 0;
        int count_0 = 0;
        int len = k;

        for (int right = 0; right < nums.size(); right++) {

            if (nums[right] == 0)
                count_0++;
            while (count_0 > k) {
                if (nums[left] == 0)
                    count_0--;
                left++;
            }
            len = max(len, right - left + 1);
        }

        return len;
    }
};